/*
 * @Description:菜单路由
 * @Version: 2.0
 * @Autor: kafei
 * @Date: 2021-12-07 17:41:06
 * @LastEditors: kafei
 * @LastEditTime: 2021-12-21 15:22:43
 */
const {
  allMenuController,
  updateMenuController,
  getMenuByIdController,
  addMenuController,
  delMenuController
} = require('../controller/menuController')
const result = require('../utils/result')
const getMenuApi = (router) => {
  router.get('/allMenu', async (ctx) => {
    const resultData = await allMenuController()
    ctx.body = resultData
  })
  router.post('/updateMenu', async (ctx) => {
    const resultData = await updateMenuController(ctx.request.body)
    ctx.body = resultData
  })
  router.post('/addMenu', async (ctx) => {
    const resultData = await addMenuController(ctx.request.body)
    ctx.body = resultData
  })

  router.post('/delMenu', async (ctx) => {
    const { id } = ctx.request.body
    if (!id) {
      result('1', '请添加id')
    }
    const resultData = await delMenuController(ctx.request.body)
    ctx.body = resultData
  })

  router.get('/getMenuById', async (ctx) => {
    const { id } = ctx.query
    if (!id) {
      result('1', '请添加id')
    }
    const resultData = await getMenuByIdController(id)
    ctx.body = resultData
  })
}
module.exports = getMenuApi

